/**
 * Copyright 2009 University of Washington This code is released under the GPL version 3 - with a copy of the license
 * included
 * 
 * @author Maya Hao Li
 * 
 */
package seedpod.webapp.view.seedpodwidgets;

import seedpod.model.AVPair;
import seedpod.model.SeedpodModel.RdbCls.FormWidget;
import seedpod.model.SeedpodModel.RdbCls.ViewWidget;
import seedpod.webapp.view.htmlwidget.Button;
import seedpod.webapp.view.htmlwidget.TextInput;

/**
 * <p>
 * Title: single cell recording data entry
 * </p>
 * <p>
 * Description: web based data entry
 * </p>
 * <p>
 * Copyright: Copyright (c) 2003
 * </p>
 * <p>
 * Company: UW Biostructure
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */

public class File extends LimsWidget {

	// public File( SlotMap att )
	// {
	// super(att);
	// }

	public File() {
	// TODO Auto-generated constructor stub
	}

	public File(AVPair avpair) {
		super( avpair );
	}

	@Override
	public FormWidget getFormWidgetType() {
		return FormWidget.FILE;
	}

	@Override
	public ViewWidget getViewWidgetType() {
		return ViewWidget.FILE;
	}

	@Override
	public String render() {
		String fileSrc = getData().toString();
		String attName = getAttribute().getName();
		TextInput fileSrcInput = new TextInput( attName, fileSrc );
		fileSrcInput.setSize( 40 );

		Button downloadButton = new Button( attName + "_btnDownload", "Download" );
		downloadButton.setJscript( "onclick=\"window.open(document.getElementById('" + getAttribute().getName() + "').value, 'download','width=500,height=500,resizable=yes');\"" );

		Button uploadButton = new Button( getAttribute().getName() + "_btnUpload", "Upload" );
		uploadButton.setJscript( "onclick=\"window.open('SimpleUpload.jsp', '" + attName + "', 'width=500,height=150,resizeable=yes');\"" );

		String out = fileSrcInput.render() + "<br> ";
		out += uploadButton.render() + "&nbsp; &nbsp;";
		out += downloadButton.render();
		return out;
	}

	@Override
	public void validateWidget() {
	/**
	 * @TODO: the file type can have multiple attributes in the database. it will be represented as a new value type in
	 *        the model.
	 */
	}

}